<?php
//session_start(); if (isset($_REQUEST['_SESSION'])) die("Get lost Muppet!");


    function getTableNames($result){
         $i = 0;                
        while ($i < mysql_num_fields($result)) {
            $info = mysql_fetch_field($result, $i);
            $tables = $info->table;
            $i++;
        }
        return $tables;       
    }
    function getTblUpdate($str){
            $createTbl = preg_match('/UPDATE\s(.*)\s/i', $str, $matches);
            $name = explode(' ', trim($matches[1]));
            return $name[0]; 
    }
   function getTblInsert($str){
        $createTbl = preg_match('/INSERT INTO\s(.*)\s/i', $str, $matches);
        if(trim($matches[1])) {
            $name = explode(' ', trim($matches[1]));
            return $name[0];
        }
        return -1;
             
    }
    function getColNames($result){
        $i = 0;                
        while ($i < mysql_num_fields($result)) {
            $info = mysql_fetch_field($result, $i);
            $fields[] = $info->name;
            $i++;
        }
        return $fields;
    }
    function getCols($tbl) {
        $cols = mysql_query("SHOW COLUMNS FROM $tbl"); 

        $i = 0;
        $fields = array();
        while ($row = mysql_fetch_assoc($cols)) {
             $fields[$i] = $row['Field'];
             $i ++;  
        }
        return $fields;

    }

function tableIndex($ind) {
    switch ($ind) {
        case 0:
            $table = $_SESSION['langas'];
            break;
        case 1:
            $table = 'mokiniai';
            break;
        case 2:
            $table = 'mokytojai';
            break;
        case 3:
            $table = 'zmones';
            break;       

    }
}
?>